// 导入axios基本配置
import instance from '../axios_config'

export default class APIBase {
  public name: string

  constructor(name: string) {
    this.name = name
  }
  // 获取所有信息
  public getAll = (params?: any) => {
    return instance({
      method: 'get',
      url: this.name,
      params
    })
  }

  // 添加信息
  public add = async (data: any) => {
    return await instance({
      method: 'post',
      url: this.name,
      data
    })
  }

  // 获取单个信息
  public getOne = async (id: string) => {
    return await instance({
      method: 'get',
      url: `${this.name}${id}/`
    })
  }
  // 修改单个信息
  public alt = async (id: string, data: any) => {
    return await instance({
      method: 'put',
      url: `${this.name}${id}/`,
      data
    })
  }
  // 删除单个信息
  public del = async (id: string) => {
    await instance({
      method: 'delete',
      url: `${this.name}${id}/`
    })
  }

  public upload = async (url: string, file: any) => {
    await instance({
      method: 'post',
      url: url,
      data: file
    })
  }
}
